package com.itheima.service.impl;

import com.itheima.dao.AccountDao;
import com.itheima.service.AccountService;
import com.itheima.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

    @Autowired
    private LogService logService;

    @Override
    //开启事物
    @Transactional(timeout = 5)
    public void transfer(String out, String in , Double money) {

        try {
            accountDao.outMoney(out,money);
            int i = 1/0;
            Thread.sleep(3000);
            accountDao.inMoney(in,money);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }



        /* try {
             accountDao.outMoney(out,money);
             int i = 1/0;
             accountDao.inMoney(in,money);
         }finally {
             logService.log(out,in,money);
         }*/
    }
}
